package com.cxj.appearance;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;

import com.waps.AppConnect;

public class ThreeActivity extends Activity {
	private Spinner timeSpinner;
	private Button queryButton;
	private static final String TAG = "TAG";
	private String[] xjyc = new String[12];

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.threeactivity);

		// 加载预测结果
		try {
			InputStream is = getResources().openRawResource(R.raw.xjyc);
			LineNumberReader fr = new LineNumberReader(new InputStreamReader(is));
			int i = 0;
			for (String line = fr.readLine(); line != null; line = fr.readLine()) {
				xjyc[i++] = line;
			}
		} catch (Exception e) {
			Log.e(TAG, e.getMessage());
		}

		timeSpinner = (Spinner) findViewById(R.id.timeSpinner);

		// 查询按钮
		queryButton = (Button) findViewById(R.id.queryButton);
		queryButton.setOnClickListener(new Button.OnClickListener() {
			@Override
			public void onClick(View v) {
				int time = timeSpinner.getSelectedItemPosition();
				Log.i(TAG, "time position is " + time);


				String testResult = xjyc[time];

				if (!MainActivity.hasEnoughRequrePoint) {// 没达到积分
					MainActivity.showDialog(testResult, ThreeActivity.this);
				}
				else
				{
					MainActivity.showResult(testResult, ThreeActivity.this);
				}
			}
		});
		
		Button owns = (Button) findViewById(R.id.moreappButton);
		owns.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View arg0) {
				// 显示自家应用列表.
				AppConnect.getInstance(ThreeActivity.this).showMore(ThreeActivity.this);
			}
		});
	}
}